package com.vkserver.server;

import com.vkserver.services.DBManager;
import com.vkserver.services.utils.Question;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;

/**
 *@author roman.prudkogliad@gmail.com
 */
@Path("/question")
public class QuestionResource {


    @GET
    @Path("/{userId}")
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public List<Question> getQuestions(@PathParam("userId") long userId) {
		List<Question> questions = new ArrayList<Question>();
		questions.addAll(DBManager.getInstance().getQuestions(userId));
		return questions;
	}



    @GET
    @Path("/{userId}/{text}")
    @Produces("text/plain")
    public String addQuestion(@PathParam("userId") long userId,
                          @PathParam("text") String text){
        return DBManager.getInstance().addQuestion(new Question(userId, text));
    }
}
